!function() {
	"use strict";
	var _this = function(selector) {
		return new _this.fn(selector || [])
	}
	//基础属性
	_this.version = '1.0.17';
	_this.dir = '';
	_this.DEBUG = (function(){
		var js = document.getElementsByTagName("script");
    	js = js[js.length-1];
    	var src = js.src ? js.src : js.getAttribute("src");
    	_this.dir = src.substring(0, src.lastIndexOf('/') + 1);
    	if(src.indexOf('#debug') !== -1){
    		window.addEventListener('error',function(e){
    			_this.log(e.error.stack, '<span style="color:#f00">出错</span> ('+e.filename+':'+e.lineno+':'+e.colno+')');
    		});
    		return true;
    	}
    	return false;
	})();
	_this.ready = function(f) {
		function _f() {
			document.removeEventListener("DOMContentLoaded", _f), window.removeEventListener("load", _f), f();
		}
		"complete" == document.readyState || "loading" != document.readyState && !document.documentElement.doScroll ? window.setTimeout(f) : (document.addEventListener("DOMContentLoaded", _f), window.addEventListener("load", _f));
	}
	_this.fn = function(selector) {
		if(typeof(selector) == "function") {
			_this.ready(selector);return undefined;
		} else {
			Object.defineProperty(this, 'length', {value: 0,writable: true});
			if(selector.nodeType && selector.nodeType == 1) { //DOM对象
				this.push(selector);
			} else if(typeof(selector) == "string") {
				for(var i = 0,doms = document.querySelectorAll(selector); i < doms.length; i++) {
					this.push(doms[i]);
				}
			} else if(typeof(selector) == "object" && selector.length) {
				for(var i = 0; i < selector.length; i++) {
					selector[i].nodeType == 1 && this.push(selector[i]);;
				}
			}
			return this;
		}
	}
	_this.extend = function(obj, arr, options){
		if(typeof(arr)!=="object")return;
		obj = typeof(obj)=="undefined" ? this : obj;
		options = options || {};
		for (var k in arr) {
			options['value'] = arr[k];
			Object.defineProperty(obj, k, options);
		}
	}
	_this.fn.extend = function(arr, options){
		_this.extend(this.prototype, arr, options)
	}
	_this.fn.extend({
		forEach: Array.prototype.forEach,
		push: Array.prototype.push,
		splice: Array.prototype.splice,
	})
	_this.log = function(obj, note, depth) {
		if(!this.DEBUG) return console.log(obj);
		var dom = this.log.dom;
		//初始化dom
		if(!dom) dom = this.log.dom = init();
		function init() {
			var boxid = 'log' + (new Date()).getTime(),
				outer = document.createElement('div'),
				log_ico = document.createElement('span'),
				exit = document.createElement('p'),
				stl = document.createElement('style'),
				log_txt = document.createElement('div');
			var cssText = '#' + boxid + '{position: fixed;bottom: 0;right: 0;width: 100%;z-index: 999999;background: #fff;color: #000;text-align: left;border-top: 1px solid #999;}' +
				'#' + boxid + ' *{padding:0;margin:0;}' +
				'#' + boxid + '>span{display: block;color:#fff;background: rgba(0,0,0,.3);width: 1em;height: 1em;line-height:1.3em;text-align: center;font-size: 3em;position: fixed;bottom: 0.6em;right: 0.6em;cursor: pointer;}' +
				'#' + boxid + '>div{display: none;background: #fff;margin-top:2em;height: 18em;padding: 0;line-height: 1.5em;overflow:auto;font-size:1em;}' +
				'#' + boxid + '>p{display: none;height: 2em;line-height: 2em;font-size: 1em;position: absolute;top: 0;right: 0.8em;cursor: pointer;color: #E74C3C;}' +
				'#' + boxid + '>div>div{margin-top: 1em}' +
				'#' + boxid + ' xmp{font-family: inherit;margin:0;display:inline;}' +
				'#' + boxid + ' i{color:#f00;display: inline-block;width: 1.5em;cursor: pointer;text-align: center;font-style: normal;}' +
				'#' + boxid + ' li{font-size: 1em;list-style-type: inherit;height:auto;line-height:1.2em}' +
				'#' + boxid + ' ul{padding-inline-start: 2em;list-style-type: disc;}' +
				'#' + boxid + ' ul ul{list-style-type: circle;}' +
				'#' + boxid + ' ul ul ul{list-style-type: square;}';

			stl.innerHTML = cssText;
			log_ico.innerText = '^';
			log_ico.addEventListener('click', function() {
				log_ico.style.display = 'none';
				log_txt.style.display = 'block';
				exit.style.display = 'block';
			});
			exit.innerText = '关闭';
			exit.addEventListener('click', function() {
				log_ico.style.display = 'block';
				log_txt.style.display = 'none';
				exit.style.display = 'none';
			});
			outer.id = boxid;
			if(window.devicePixelRatio > 1) {
				outer.style.fontSize = (document.documentElement.clientWidth / 40) + 'px';
			} else {
				outer.style.fontSize = '14px';
			}
			document.querySelector('head').appendChild(stl);
			document.querySelector('html').appendChild(outer);
			outer.appendChild(log_txt);
			outer.appendChild(exit);
			outer.appendChild(log_ico);

			log_txt.openfunc = 'open' + boxid;
			window[log_txt.openfunc] = function(dom) {
				var ul = dom.parentNode.querySelector('ul');
				if(dom.innerText == '-') {
					dom.innerText = '+';
					ul.style.display = 'none';
				} else {
					dom.innerText = '-';
					ul.style.display = 'block';
				}
			}
			return log_txt;
		}
		//渲染数据
		function loop(data, depth) {
			var html = '';
			if(typeof(data) == "object") {
				if(data == null) {
					html += 'null';
				} else {
					if(depth >= 0) {
						html += '<i onclick="' + dom.openfunc + '(this)" style="">-</i><ul>';
						for(var k in data) {
							html += '<li>' + k + ' : ' + loop(data[k], (depth - 1)) + '</li>';
						}
						html += '</ul>';
					} else {
						html += Object.prototype.toString.call(data);
					}
				}
			} else {
				html = '<xmp>' + data + '</xmp>';
			}
			return html;
		}
		note = note || 'default_name';
		dom.innerHTML += '<div><span style="color:#007AFF">' + note + '</span>: ' + loop(obj, depth || 2) + '</div>';
	}
	//type、each、merge、trim、param、reparam、url、loadJs、ajax
	_this.type = function(obj){
		var str = Object.prototype.toString.call(obj);
		return str.substring(8,str.length-1);
	}
	_this.each = function(obj, callback) {
		for (var i in obj ) {
			if ( callback.call( obj[ i ], i, obj[ i ] ) === false ) break;
		}
	}
	_this.fn.extend({
		each: function(callback){
			_this.each(this,callback)
			return this;
		}
	})
	_this.merge = function(obj1,obj2){
		if (_this.type(obj1)=='Array' && _this.type(obj2)=='Array') {
			var res = [];
		} else{
			var res = {};
			_this.extend(res,{length:0,push: Array.prototype.push},{writable: true});
		}
		function loop(i,row){
			i.toString().match(/^\d+$/)? res.push(row) : (res[i]=row);
		}
		_this.each(obj1,loop);
		_this.each(obj2,loop);
		return res;
	}
	_this.trim = function(str, mask){
		if(str.trim && !mask){
            return str.trim();
        }
        if(mask){
            mask = mask.replace(/([\$\(\)\*\+\?\.\[\]\\\^\{\}\|]){1}/g, '\\$1');
            var reg = new RegExp('^[\\s\\uFEFF\\xA0' + mask + ']+|[\\s\\uFEFF\\xA0' + mask + ']+$', 'g');
        }else{
            var reg = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;
        }
        return str.replace(reg, '');
	}
	_this.reparam = function(str){
        var obj = {};
        var str_arr = str.split('&');
        for(var j = 0; j < str_arr.length; j++){
        	if(!str_arr[j] || str_arr[j].indexOf('=')==-1) continue;
            var info = str_arr[j].split('=');
            if(!info[0]) continue;
            var v = info[1];
            var ks = info[0].match(/^([^\[]+)(\[(.*)\])?$/);
            var k = ks[1];
            if(ks[2]){
                var eval_data = 'obj["' + k + '"]';
                var index_k = k;
                eval(eval_data + '=typeof(' + eval_data + ')=="object"?' + eval_data + ':[]');
                var k2 = ks[3].split('][');
                for(var i = 0; i < k2.length; i++){
                    var is_last = (i >= k2.length - 1);
                    var value = is_last ? decodeURIComponent(v) : [];
                    if(k2[i] == ''){
                        var index = eval(eval_data+'.push(value)')-1;
                        if(!is_last) eval_data += '[' + index + ']';
                    }else{
                        eval_data += '["' + k2[i] + '"]';
                        eval(eval_data + '=typeof(' + eval_data + ')!="undefined"&&!is_last?' + eval_data + ':value;');
                    }
                }
            }else{
                obj[k] = decodeURIComponent(v);
            }
        }
        return obj;
	}
	_this.param = function(obj){
		var param_arr = [];
        function loop(name, value){
            if(typeof(value) == "object"){
                for(var k in value){
                    loop(name + '[' + k + ']', value[k])
                }
            }else{
                param_arr.push(name + '=' + encodeURIComponent(value));
            }
        }
        if(typeof(obj)=='string'){
        	 return obj;
        }else if(typeof(obj) == "object"){
        	for(var k in obj){
	            loop(k, obj[k]);
	        }
        }else{
        	return Object.prototype.toString.call(obj);
        }
        return param_arr.join('&');
	}
	_this.url = function(str){
		var loc = window.location;
		if(str.indexOf('http')===0 || str.indexOf('file')===0) return str;
		var origin = loc.origin || (loc.protocol+'//'+loc.host);
		if(str[0]=='/') return origin+str;
		var arrpath = loc.pathname.substring(1).split('/');
		arrpath.pop();
		for (var i=0,arrsrc = str.split('/'); i<arrsrc.length; i++) {
			switch (arrsrc[i]){
				case '.':break;
				case '..':arrpath.pop();break;
				default:arrpath.push(arrsrc[i]);break;
			}
		}
		return origin+'/'+arrpath.join('/');
	}
	_this.loadJs = function(srcs, callback){
		var loadJsList = _this.loadJs.list ? _this.loadJs.list : (_this.loadJs.list={}); 
    	srcs = typeof(srcs)=="string"?[srcs]:srcs;
		var length = srcs.length;
		var scriptNodes=[];
		function callback_action(){
			--length == 0 && typeof(callback)=="function" && callback.call(loadJsList,scriptNodes);
		}
		var arrjs = document.querySelectorAll('script');
		var loaded=[];
		for (var i = 0; i < arrjs.length; i++) {
			loaded.push(_this.url(arrjs[i].src));
		}
		for (var i = 0; i < srcs.length; i++) {
			var src = _this.url(srcs[i]);
			if (!loadJsList[src]){
				var loaded_index = loaded.indexOf(src);
				loadJsList[src]= loaded_index == -1 ? {status:false,loading:false,dom:undefined,callbacks:[]} : {status:true,loading:false,dom:arrjs[loaded_index],callbacks:[]};
			}
			if(loadJsList[src].status){
				scriptNodes.push(loadJsList[src].dom);
				callback_action();
			}else{
				loadJsList[src].callbacks.push(callback_action);
				if (!loadJsList[src].loading) {
					var script = document.createElement("script");
					loadJsList[src].dom = script;
					script.onload = function() {
						var k = this.list_key;
						loadJsList[k].loading = false;
						loadJsList[k].status = true;
						for (; 0 < loadJsList[k].callbacks.length;) {
							loadJsList[k].callbacks[0]();
							loadJsList[k].callbacks.splice(0,1);
						}
					}
					script.onerror = function(e){
						var k = this.list_key;
						loadJsList[k].loading = false;
						_this.log(this.src+'加载失败','<span style="color:#f00">loadJs出错</span>');
					}
					script.src = src;
					script.list_key = src;
					document.getElementsByTagName("head")[0].appendChild(script);
					loadJsList[src].loading = true;
					scriptNodes.push(script);
				}
			}
		}
		return 
    }
	_this.ajax = function(setup){
		setup = setup || {};
		setup.type = setup.type ? setup.type.toUpperCase() : 'GET';
		setup.dataType = setup.dataType ? setup.dataType.toUpperCase() : 'JSON';
		setup.url = setup.url || location.href;
		setup.async = !!setup.async;
		setup.defaultContentType = 'application/x-www-form-urlencoded'
		//数据处理
		setup.data = setup.data || null;
		if(setup.data){
			var dataTypeIndex = ['String','Array','Object','URLSearchParams','Blob','FormData'].indexOf(_this.type(setup.data));
			if(dataTypeIndex == -1) throw '发送数据类型错误';
			if (setup.dataType == 'JSONP' || setup.type == 'GET') {
				setup.url += (setup.url.indexOf('?') == -1?'?':'&') + _this.param(setup.data);
				setup.data=null;
			}else{
				if(dataTypeIndex < 3) setup.data = _this.param(setup.data);
				if(dataTypeIndex == 4) {
					var blod = setup.data;
					setup.data =  new FormData();
					setup.data.append('blob', blod);
				}
				if(dataTypeIndex > 3) setup.defaultContentType = '';
			}
		}
		setup.contentType = setup.contentType || setup.defaultContentType
		if (setup.dataType=='JSONP') {
			var callbackName = 'jsonp_'+Math.random().toString().substr(2);
			window[callbackName] = setup.success;
			setup.url += (setup.url.indexOf('?') == -1?'?':'&') + (setup.jsonp || 'callback') + '=' + callbackName;
			var script = document.createElement("script");
			script.onload = function() {
				typeof(setup.complete)=="function" && setup.complete(script,'200 OK');
				document.getElementsByTagName("head")[0].removeChild(script);
			}
			script.onerror = function(e){
				typeof(setup.error)=="function" && setup.error(script,'404 Not Found');
				typeof(setup.complete)=="function" && setup.complete(script,'404 Not Found');
				document.getElementsByTagName("head")[0].removeChild(script);
			}
			script.src = setup.url;
			document.getElementsByTagName("head")[0].appendChild(script);
			return script;
		}
		var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		xhr.open(setup.type, setup.url, setup.async, setup.user, setup.password);
		//设置头信息
		setup.contentType && xhr.setRequestHeader("Content-Type", setup.contentType);
		xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
		if (_this.type(setup.headers) == 'Object') {
			for (var k in setup.headers) {
				xhr.setRequestHeader(k, setup.headers[k])
			}
		}
		setup.beforeSend && setup.beforeSend(xhr);
		//进度
		if(xhr.upload && setup.progress){
			xhr.upload.addEventListener('progress', function(e) {
				setup.progress(e.loaded,e.total);
			}, false);
		}
		var ac = function(xhr){
			if(xhr && xhr.readyState == 4) {
				if (xhr.status != 200) {
					typeof(setup.error)=="function" && setup.error(xhr,xhr.statusText);
				}else{
					var res = xhr.getResponseHeader('Content-Type').indexOf('/json')>0 ? JSON.parse(xhr.responseText) : xhr.responseText;
					typeof(setup.success)=="function" && setup.success(res);
				}
				typeof(setup.complete)=="function" && setup.complete(xhr,xhr.statusText);
			}
		};
		xhr.onreadystatechange = function(){ac(xhr)};
		xhr.send(setup.data);
		return xhr;
	}
	/*--------------------Document------------------*/
	//hasClass、addClass、removeClass、toggleClass
	_this.hasClass = function(dom,className){
		return dom.classList ? dom.classList.contains(className) : (dom.className && dom.className.split(' ').indexOf(className)!=-1);
	}
	_this.addClass = function(dom,className){
		if (_this.hasClass(dom,className)) return;
		dom.classList ? dom.classList.add(className) : (dom.className += (dom.className?' ':''+className));
	}
	_this.removeClass = function(dom,className){
		if (!_this.hasClass(dom,className)) return;
		if (dom.classList) {
			dom.classList.remove(className)
		}else{
			var classList = dom.className.split(' ');
			classList.splice(classList.indexOf(className),1);
			dom.className = classList.join(' ');
		}
	}
	_this.toggleClass = function(dom,className){
		dom.classList ? dom.classList.toggle(className) : (_this.hasClass(dom,className)?_this.removeClass(dom,className):_this.addClass(dom,className));
	}
	_this.fn.extend({
		hasClass: function(className){
			for (var i = 0; i < this.length; i++) {
				if(_this.hasClass(this[i],className)) return true;
			}
			return false;
		},
		addClass: function(className){
			this.forEach(function(dom){
				_this.addClass(dom,className);
			})
			return this;
		},
		removeClass: function(className){
			this.forEach(function(dom){
				_this.removeClass(dom,className);
			})
			return this;
		},
		toggleClass: function(className){
			this.forEach(function(dom){
				_this.toggleClass(dom,className);
			})
			return this;
		}
	})
	//text、html、attr、removeAttr、val、css
	_this.fn.extend({
		text:function(str){
			if(typeof(str)=="undefined") return this.length ? this[0].innerText : false;
			this.forEach(function(dom){
				dom.innerText = str;
			})
			return this;
		},
		html: function(str){
			if(typeof(str)=="undefined") return this.length ? this[0].innerHTML : false;
			this.forEach(function(dom){
				dom.innerHTML = str;
			})
			return this;
		},
		attr: function(name, value){
			if(typeof(name)=="string" && typeof(value)=="undefined") return this.length ? this[0].getAttribute(name) : false;
			this.forEach(function(dom){
				if (typeof(name)=="string") {
					dom.setAttribute(name,value);
				} else{
					for (var k in name) {
						dom.setAttribute(k,name[k]);
					}
				}
			})
			return this;
		},
		removeAttr: function(name){
			this.forEach(function(dom){
				dom.removeAttribute(name);
			})
			return this;
		},
		val: function(value){
			if(typeof(value)=="undefined") return this.length ? this[0].value : false;
			this.forEach(function(dom){
				dom.value = value;
			})
			return this;
		},
		css: function(name, value){
			var obj = {};
			if (typeof(name)=="string") {
				if(name.indexOf(';')!==-1){
					name.split(';').forEach(function(row){
						if(!row) return;
						var kv = row.split(':',2);
						obj[kv[0]] = kv[1];
					})
				}else if(typeof(value)=="undefined"){
					return this.length ? (this[0].style[name] ? this[0].style[name] : (window.getComputedStyle ? getComputedStyle(this[0],null)[name] : this[0].currentStyle[name]) ) : false;
				}else{
					obj[name] = value;
				}
			}else if(typeof(name)=="object"){
				obj = name;
			}
			this.forEach(function(dom){
				for (var k in obj) {
					dom.style[k] = obj[k];
				}
			})
			return this;
		}
	})
	//eq、find、parent、parents
	_this.fn.extend({
		eq: function(index){
			return new _this.fn(this[index] || []);
		},
		find: function(selector){
			if(!selector) return false;
			var doms = [];
			this.forEach(function(dom){
				$.each(dom.querySelectorAll(selector),function(){doms.push(this)})
			})
			return new _this.fn(doms);
		},
		parent: function(selector){
			var limt_nodes = [];
			if(selector) $.each(document.querySelectorAll(selector),function(){limt_nodes.push(this)});
			var docs=[];
			this.forEach(function(dom){
				if(!dom.parentNode || dom.parentNode.nodeType !== 1) return;
				if(docs.indexOf(dom.parentNode) == -1 && (!selector || limt_nodes.indexOf(dom.parentNode) !== -1)) docs.push(dom.parentNode);
			})
			return new _this.fn(docs);
		},
		parents: function(selector){
			var limt_nodes = [];
			if(selector) $.each(document.querySelectorAll(selector),function(){limt_nodes.push(this)});
			var docs=[];
			this.forEach(function(dom){
				while (dom.parentNode && dom.parentNode.nodeType == 1){
					dom = dom.parentNode;
					if(docs.indexOf(dom) == -1 && (!selector || limt_nodes.indexOf(dom) !== -1)) docs.push(dom); 
				}
			})
			return new _this.fn(docs);
		}
	})
	//append、prepend、after、before、remove
	//字符串转DOM节点
	function strtonodes(str){
		var istbody = !!str.match(/^\<tbody.+tbody>$/);
		var istr = !!str.match(/^\<tr.+tr>$/);
		var istd = !!str.match(/^\<td.+td>$/);
		var isth = !!str.match(/^\<th.+th>$/);
		var outer = document.createElement(istd||isth?'tr':(istr?'tbody':(istbody?'table':'div')));
		outer.innerHTML = str;
		var nodes = outer.childNodes;
		return nodes;
	}
	_this.fn.extend({
		append: function(content){
			if(typeof(content)=="undefined") return this;
			var nodes = typeof(content)=="string" ? strtonodes(content) : (content.nodeType && content.nodeType==1 ? [content] : []);
			this.forEach(function(dom){
				if (dom.nodeType !== 1 && dom.nodeType !== 11 && dom.nodeType !== 9) return;
				for (var i = 0; i < nodes.length; i++) {
					var node = typeof(content)=="string" ? nodes[i].cloneNode(true) : nodes[i];
					dom.appendChild(node);
				}
			})
			return this;
		},
		prepend: function(content){
			if(typeof(content)=="undefined") return this;
			var nodes = typeof(content)=="string" ? strtonodes(content) : (content.nodeType && content.nodeType==1 ? [content] : []);
			this.forEach(function(dom){
				if (dom.nodeType !== 1 && dom.nodeType !== 11 && dom.nodeType !== 9) return;
				var target = dom.firstChild;
				for (var i = 0; i < nodes.length; i++) {
					var node = typeof(content)=="string" ? nodes[i].cloneNode(true) : nodes[i];
					dom.insertBefore(node, target);
				}
			})
			return this;
		},
		after: function(content){
			if(typeof(content)=="undefined") return this;
			var nodes = typeof(content)=="string" ? strtonodes(content) : (content.nodeType && content.nodeType==1 ? [content] : []);
			this.forEach(function(dom){
				var parent = dom.parentNode;
				if(!parent)return;
				if (parent.nodeType !== 1 && parent.nodeType !== 11 && parent.nodeType !== 9) return;
				var target = dom.nextSibling;
				for (var i = 0; i < nodes.length; i++) {
					var node = typeof(content)=="string" ? nodes[i].cloneNode(true) : nodes[i];
					parent.insertBefore(node, target);
				}
			})
			return this;
		},
		before: function(content){
			if(typeof(content)=="undefined") return this;
			var nodes = typeof(content)=="string" ? strtonodes(content) : (content.nodeType && content.nodeType==1 ? [content] : []);
			this.forEach(function(dom){
				var parent = dom.parentNode;
				if(!parent)return;
				if (parent.nodeType !== 1 && parent.nodeType !== 11 && parent.nodeType !== 9) return;
				var target = dom;
				for (var i = 0; i < nodes.length; i++) {
					var node = typeof(content)=="string" ? nodes[i].cloneNode(true) : nodes[i];
					parent.insertBefore(node, target);
				}
			})
			return this;
		},
		remove: function(selector){
			var limt_nodes = [];
			if(selector) $.each(document.querySelectorAll(selector),function(){limt_nodes.push(this)});
			this.forEach(function(dom){
				if (!dom.parentNode) return;
				if((!selector || limt_nodes.indexOf(dom) == -1)) dom.parentNode.removeChild( dom );
			})
			return this;
		}
	})
	//on、off
	_this.fn.extend({
		on: function(etype, callback, useCapture){
			var k = 'eventCallbackList'+(useCapture?'Capture':'Bubbling')
			this.forEach(function(dom){
				dom[k] = dom[k] || [];
				dom[k][etype] = dom[k][etype] || [];
				dom[k][etype].push(callback);
				dom.addEventListener(etype,callback,useCapture);
			})
			return this;
		},
		off: function(etype, useCapture){
			var k = 'eventCallbackList'+(useCapture?'Capture':'Bubbling')
			this.forEach(function(dom){
				dom[k] = dom[k] || [];
				dom[k][etype] = dom[k][etype] || [];
				if(dom[k][etype]) for(;dom[k][etype].length;){
					dom.removeEventListener(etype,dom[k][etype][0]);
					dom[k][etype].splice(0,1);
				}
			})
			return this;
		}
	})
	var extend_fns={};
	['blur','focus','focusin','focusout','resize','scroll','click','dblclick','mousedown','mouseup','mousemove','mouseover','mouseout','mouseenter','mouseleave','change','select','submit','keydown','keypress','keyup','contextmenu'].forEach(function(name){
		extend_fns[name] = function(callback){
			this.on(name,callback)
		}
	});
	_this.fn.extend(extend_fns);
	//show、hide
	_this.fn.extend({
		show: function(time){
			this.forEach(function(dom){
				dom.hideTimeoutHander && clearTimeout(dom.hideTimeoutHander);
				if(dom.style.display=='none'){
					dom.style.display = '';
				}
				if($(dom).css('display')=='none'){
					dom.style.display = 'block';
				}
				if (time) {
					dom.style.opacity = 0;
					dom.style.transition = 'opacity '+(time/1000)+'s';
					setTimeout(function(){dom.style.opacity=1;});
					dom.showTimeoutHander = setTimeout(function(){dom.style.transition='';dom.style.opacity='';},time);
				}
			})
			return this;
		},
		hide: function(time){
			this.forEach(function(dom){
				dom.showTimeoutHander && clearTimeout(dom.showTimeoutHander);
				if (time) {
					dom.style.opacity = 1;
					dom.style.transition = 'opacity '+(time/1000)+'s';
					setTimeout(function(){dom.style.opacity=0;});
					dom.hideTimeoutHander = setTimeout(function(){dom.style.transition='';dom.style.opacity='';dom.style.display = 'none';},time);
				}else{
					dom.style.display = 'none';
				}
			})
			return this;
		}
	})
	//serializeArray、serialize
	_this.fn.extend({
		serializeArray: function(){
			var arr = [];
			this.forEach(function(dom){
				if(dom.tagName != 'FORM')return;
				if (FormData.prototype.entries) {
					( new Map((new FormData(dom)).entries()) ) .forEach(function(val,name){
						arr.push({name: name, value: val});
					})
				} else{
					var inputs = dom.querySelectorAll('input,select,textarea');
					for (var i = 0; i < inputs.length; i++) {
			        	if(!inputs[i].name) continue;
			            if(['submit','button'].indexOf(inputs[i].type)!==-1) continue;
			            if(['checkbox','radio'].indexOf(inputs[i].type)!==-1 && !inputs[i].checked) continue;
			            if(inputs[i].type=='file'){
			            	for (var f = 0; f < inputs[i].files.length; f++) {
			            		arr.push({name: inputs[i].name, value: inputs[i].files[f]});
			            	}
			            }else{
			            	arr.push({name: inputs[i].name, value: inputs[i].value});
			            }
			        }
				}
			})
			return arr;
		},
		serialize: function(notencode){
			var arr = this.serializeArray();
			var param='';
			arr.forEach(function(row){
				param += '&'+row.name+'='+(notencode ? row.value : encodeURIComponent(row.value));
			})
			return param.substring(1);
		}
	})
	//screenOffsetPage、domOffsetScreen、domOffsetPage、domOffsetParent、eventOffsetScreen、eventOffsetTarget、eventOffsetDom
	/**
     * 屏幕相对于页面的偏移
     * @param {Object|Number} to 偏移跳转到坐标to,格式{x:像素,y:像素}
     * @param {Object|Number} op [speed]动画执行速度(px/s)/[time]动画执行时间(毫秒)，传入Number表示time
     * @param {Function} callback 动画执行结束后执行的回调函数
     */
    _this.screenOffsetPage = function(to, op, callback){
        var res = {x: 0, y: 0};
        res.x = document.documentElement.scrollLeft || document.body.scrollLeft || 0;
        res.y = document.documentElement.scrollTop || document.body.scrollTop || 0;
        //没有to参数，直接返回定位，不执行锚点跳转
        if(typeof(to)=='undefined') return res;
        //requestAnimationFrame兼容
        window.requestAnimFrame = (function(){
            return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function(){
                    if(typeof(arguments[0]) == 'function'){
                        return window.setTimeout(arguments[0], 1000 / 60);
                    }
                };
        })();
        function removeAction(){
        	_this.screenOffsetPage.th && (window.cancelAnimationFrame || window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame || window.clearTimeout)(_this.screenOffsetPage.th)
        }
        removeAction();
        if(typeof(op) == 'number') op = {time: op};
        op = typeof(op)=='undefined'?{time: 1}:(typeof(op) == 'number'?{time: op}:op);
        to = typeof(to) == 'number' ? {y:to} : to;
        to.x = typeof(to.x) == 'undefined' ? res.x : to.x;
        to.y = typeof(to.y) == 'undefined' ? res.y : to.y;
        var start_time = (new Date()).getTime();
        var time = op.time;
        if(op.speed){
        	time = Math.max(Math.abs(to.x - res.x), Math.abs(to.y - res.y)) / op.speed * 1000;
        }
        function loop(){
        	var run_time = (new Date()).getTime() - start_time;
        	var bn = Math.min(run_time/time,1);
        	var now = {
	            x: res.x + ((to.x - res.x) * bn),
	            y: res.y + ((to.y - res.y) * bn)
	        };
            document.body.scrollLeft = now.x;
            document.body.scrollTop = now.y;
            document.documentElement.scrollLeft = now.x;
            document.documentElement.scrollTop = now.y;
            if(bn >= 1) return typeof(callback)=="function" && callback();
            _this.screenOffsetPage.th = requestAnimationFrame(loop);
        }
        setTimeout(loop, 1000 / 60);//此处需要延迟执行，否则可能会被系统默认还原
        return res;
    }
    /**
     * 元素相对于屏幕的偏移
     * @param {Object} dom Document元素
     */
    _this.domOffsetScreen = function(dom){
    	var r =  dom.getBoundingClientRect();
    	return {x:r.left ,y:r.top};
    }
    /**
     * 元素相对于页面的偏移【浮动定位的子元素相对于浮动定位元素】
     * @param {Object} dom Document元素
     */
    _this.domOffsetPage = function(dom){
        //循环获取父级元素的offsetTop
        var dos = _this.domOffsetScreen(dom);
        var sop = _this.screenOffsetPage();
        return {x: dos.x + sop.x, y: dos.y + sop.y};
    }
    /**
     * 元素doc相对于父级元素parent的偏移
     * @param {Object} dom Document元素
     * @param {Object} parent 指定父元素【不填为第一个父级元素】
     */
    _this.domOffsetParent = function(dom, parent){
        parent = parent || dom.parentNode;
        if(!parent) return {x: 0, y: 0};
        var m = _this.domOffsetScreen(dom);
        var p = _this.domOffsetScreen(parent);
        return {x: m.x - p.x, y: m.y - p.y}
    }
    /**
     * 获取事件触发定位，相对于屏幕
     * @param {Object} e
     */
    _this.eventOffsetScreen = function(e){
        e = e || window.event;
        if (e.changedTouches) {
        	var res = [];
        	if (window.event.type == 'touchend'){
        		res.push({x: e.changedTouches[0].clientX, y: e.changedTouches[0].clientY});
        	}
        	for (var i = 0; i < e.touches.length; i++) {
        		res.push({x: e.touches[i].clientX, y: e.touches[i].clientY})
        	}
        	if (res.length) {
        		res.x = res[0].x;res.y = res[0].y;
        	} else{
        		res={x:0,y:0}
        	}
        	return res;
        } else{
        	return {x: e.clientX, y: e.clientY};
        }
    }
    /**
     * 获取事件触发定位，相对于触发DOM节点
     * @param {Object} e window.event对象,默认为window.event
     */
    _this.eventOffsetTarget = function(e){
        e = e || window.event;
        if (e.changedTouches) {
        	var res = [];
            var d_xy = this.domOffsetScreen(e.target);
            var e_xy = this.eventOffsetScreen(e);
        	for (var i = 0; i < e_xy.length; i++) {
        		res.push({x: e_xy[i].x - d_xy.x, y: e_xy[i].y - d_xy.y})
        	}
        	res.x = e_xy.x - d_xy.x;
        	res.y = e_xy.y - d_xy.y;
        	return res;
        } else{
        	return {x: e.offsetX, y: e.offsetY};
        }
    }
    /**
     * 获取事件触发定位，相对于DOM节点
     * @param {Object} dom 指定DOM节点元素【不填返回{x:0,y:0}】
     * @param {Object} e window.event对象,默认为window.event
     */
	_this.eventOffsetDom = function(dom,e){
		if(typeof(dom)=='undefined') return {x:0,y:0};
        e = e || window.event;
		if(dom==e.target) return this.eventOffsetTarget(e);
        var d_xy = this.domOffsetScreen(dom);
        var e_xy = this.eventOffsetScreen(e);
        var res = [];
        if(e_xy.length){
        	for (var i = 0; i < e_xy.length; i++) {
        		res.push({x: e_xy[i].x - d_xy.x, y: e_xy[i].y - d_xy.y})
        	}
        }
        res.x = e_xy.x - d_xy.x;
        res.y = e_xy.y - d_xy.y;
        return res;
    }
	_this.fn.extend({
		domOffsetPage  : function(){
            return _this.domOffsetPage(this[0]);
        },
        domOffsetScreen: function(){
            return _this.domOffsetScreen(this[0]);
        },
        domOffsetParent: function(parent){
            return _this.domOffsetParent(this[0], parent);
        },
        eventOffsetDom: function(){
            return _this.eventOffsetDom(this[0]);
        }
	})
	
	/**
     * 格式化时间样式
     * @param {String} fmt 样式规则[YMDHISWymdhisw]
     * @param {Date|Number} time 需要格式化的时间对象或者时间戳(毫秒)
     */
	_this.date = function(fmt, time){
		time = _this.type(time) == 'Date' ? time : (time ? new Date(time) : new Date());
		var y = time.getFullYear(),
            m = time.getMonth() + 1,
            d = time.getDate(),
            h = time.getHours(),
            i = time.getMinutes(),
            s = time.getSeconds(),
            w = time.getDay();
        var list = {
            'Y': y,'y':y,
            'M': m < 10 ? ('0' + m) : m,'m':m,
            'D': d < 10 ? ('0' + d) : d,'d':d,
            'H': h < 10 ? ('0' + h) : h,'h':h,
            'I': i < 10 ? ('0' + i) : i,'i':i,
            'S': s < 10 ? ('0' + s) : s,'s':s,
            'W': ['日','一','二','三','四','五','六'][w],
            'w': ['7','1','2','3','4','5','6'][w]
        }
        var t=[];
        fmt = fmt.replace(/\"/g,'\\"').replace(/\\(Y|M|D|H|I|S|W|y|m|d|h|i|s|w)/g,function(mt,t1){
			var js = '"+t['+t.length+']+"';
			t.push(t1);
            return js;
        }).replace(/(Y|M|D|H|I|S|W|y|m|d|h|i|s|w)/g,'"+list["$1"]+"');;
        return eval('"'+fmt+'"');
	}
    Date.prototype.date = function(fmt){return _this.date(fmt, this)}
	window['$'] = window['jQuery'] = _this;
}();
